Skip to content

feat: add MagiCompilerBackend with static/dynamic routing#685

Merged
lixinqi merged 2 commits intoPaddlePaddle:developfrom
fangfangssj:feat/magi-compiler-backend
Mar 30, 2026
Merged

feat: add MagiCompilerBackend with static/dynamic routing#685
lixinqi merged 2 commits intoPaddlePaddle:developfrom
fangfangssj:feat/magi-compiler-backend

Conversation

@fangfangssj
Copy link
Copy Markdown
Contributor

Summary

  • 新增 MagiCompilerBackend,将 magi_compiler 接入 graph_net_bench 编译器测试框架
  • 静态路径input_tensor_constraints.py 中无 sympy 动态维度):走 TORCH_COMPILE + inductor,通过 magi_compiler._api._magi_compile_class 绕过公开 API 对非空 dynamic_arg_dims 的 assert
  • 动态路径(存在 sympy 符号维度):走 MAGI_COMPILE piecewise,通过 magi_compiler.magi_compile 正常编译
  • _load_dynamic_arg_dims 读取模型目录下的 input_tensor_constraints.py,仅提取含 sympy.Basic 的真实动态维度,避免 magi_compiler 默认启发式将所有 Tensor 标为 dim-0 动态导致的 ConstraintViolationError
  • test_compiler.py 中注册 magi_compiler 编译器名

Test plan

  • 静态模型(Qwen2.5-0.5B):magi_compiler 静态路径,status: success,~2.2x speedup
  • 动态模型(seresnet50.a1_in1k):magi_compiler 动态路径,status: success

🤖 Generated with Claude Code

Integrate magi_compiler as a new backend for graph_net_bench:
- Static path (no sympy dynamic dims): TORCH_COMPILE + inductor via
  magi_compiler._api._magi_compile_class, bypassing the public API assert
  that requires non-empty dynamic_arg_dims
- Dynamic path (sympy symbols in input_tensor_constraints.py): MAGI_COMPILE
  piecewise via magi_compiler.magi_compile

_load_dynamic_arg_dims reads input_tensor_constraints.py from the model's
source directory and extracts only the truly dynamic dims (args whose shape
contains sympy.Basic symbols), avoiding ConstraintViolationError caused by
magi_compiler's default heuristic marking all tensors as dim-0 dynamic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Mar 29, 2026

Thanks for your contribution!

@lixinqi lixinqi merged commit 9c3a864 into PaddlePaddle:develop Mar 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants